    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

public class controller implements MouseListener, MouseMotionListener{
       
       Avoider avoid;
       Cursor c;
       
       public controller(Avoider avoid){
       this.avoid = avoid;
       c = avoid.getCursor(); //get the current cursor icon
       }
       
       public void origCursor(){avoid.setCursor(c);} //set to original
       public void mousePressed(MouseEvent evt) { }
       public void mouseReleased(MouseEvent evt)
       {  if(!avoid.getFreeze())
          {
            if(!avoid.getRun()){
		    avoid.setRun(true);
		    avoid.setStop(true);
            mouseMoved(evt);

                         //Hide Cursor in program, it replaces the cursor with a
			 //transparent image file
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Image image = toolkit.createImage(new byte[]{0});
            Cursor noCursor = toolkit.createCustomCursor(image, new Point(1,1),
                                             "cursor.png");
            avoid.setCursor(noCursor);}
         }
       avoid.setFreeze(false);
       }
       public void mouseDragged(MouseEvent evt) {
		   mouseMoved(evt);
		   }
       public void mouseMoved(MouseEvent evt)
       {  
            if(avoid.getRun())
            { //set block coordiantes to follow mouse
                int x = evt.getX();
                int y = evt.getY();
		    //follow cursor
		    avoid.set1(x-15,y-15);
                avoid.drawSurface.repaint();
            }
         }
      
       public void mouseClicked(MouseEvent evt) {}
       public void mouseEntered(MouseEvent evt) {}
       public void mouseExited(MouseEvent evt) {}

       }
